< previous page page_736 next page >

Page 736
Listing 19.10. continued
    Dim strErrorMsg As String * sqlMaxMsgLen
    Dim intErrorMsgLen As Integer
    Dim intOutLen As Integer
    '
    Dim lngErrCode As Long
    Dim strErrCode As String
    Dim intResult As Integer
    Dim intTemp As Integer
    '
    strSQLState = String(16, 0)
    strErrorMsg = String(sqlMaxMsgLen - 1, 0)
    '
    Do
        intResult = sqlError(hEnv, hDbc, hStmt, strSQLState, lngErrCode,
strErrorMsg, Len(strErrorMsg), intErrorMsgLen)

        If intResult = sqlSuccess Or intResult = sqlSuccessWithInfo Then
            If intErrorMsgLen = 0 Then
                Err.Raise vbObjectError + 9, App.EXEName, "Success or
SuccessWithInfo Error"
            Else
                If lngErrCode = 0 Then
                    strErrCode = ""
                Else
                    strErrCode = Trim(CStr(lngErrCode)) & " "
                End If
                Err.Raise vbObjectError + 10, App.EXEName, "<" & strMsg & "> " &
strErrCode & Left(strErrorMsg, intErrorMsgLen)
            End If
        End If
    Loop Until intResult <> sqlSuccess
    '
End Sub
The routine in Listing 19.10 checks the state of the error code and returns any messages it can find. There are times when the error code is set by ODBC, but no message is returned. The routine checks for this and creates its own message, if needed.
Save this class module before you continue with the last set of ODBC library routines.
High-Level Routines
The last set of ODBC library routines deals primarily with the duties required to make Visual Basic capable of displaying, reading, and writing data via the ODBC interface. These routines take the datasets returned by ODBC and store them in Visual Basic list and grid controls. These controls then are used as holding areas by your Visual Basic program for filling and updating textboxes on your data-entry form. This method of storing result sets in a Visual Basic control reduces the amount of traffic over the ODBC link and improves the response time of your program.

 
< previous page page_736 next page >

If you like this book, buy it!